﻿<Window x:Class="GraphSharp.Sample.TestCompoundLayout"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sample="clr-namespace:GraphSharp.Sample"
		xmlns:GraphSharp_Controls="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls"
        xmlns:graph="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls"
        xmlns:Controls="clr-namespace:WPFExtensions.Controls;assembly=WPFExtensions"
		xmlns:WPFExtensions_AttachedBehaviours="clr-namespace:WPFExtensions.AttachedBehaviours;assembly=WPFExtensions"
        Title="TestCompoundLayout"
        Height="300"
        Width="300">
    <DockPanel>
        <DockPanel.Resources>
		
			<ResourceDictionary>
				<ResourceDictionary.MergedDictionaries>
					<ResourceDictionary Source="Resources\PocGraphDataTemplates.xaml"/>
				</ResourceDictionary.MergedDictionaries>
				
				<sample:PocVertexToLayoutModeConverter x:Key="layoutModeConverter" />

            	<Style TargetType="{x:Type graph:CompoundVertexControl}">
					<Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type GraphSharp_Controls:CompoundVertexControl}">
                    <Border BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            Background="{TemplateBinding Background}">
                        <GroupBox>
                            <GroupBox.Header>
                                <ContentPresenter Content="{TemplateBinding Vertex}"/>
                            </GroupBox.Header>

                            <ItemsControl x:Name="PART_InnerCanvas"
                                          ItemsSource="{TemplateBinding Vertices}">
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <StackPanel Orientation="Vertical" />
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                            </ItemsControl>
                        </GroupBox>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        
        <Setter Property="GraphSharp_Controls:GraphElementBehaviour.HighlightTrigger"
                Value="{Binding RelativeSource={RelativeSource Self},Path=IsMouseOver}" />
        <Setter Property="WPFExtensions_AttachedBehaviours:DragBehaviour.IsDragEnabled"
                Value="True" />
        <Setter Property="WPFExtensions_AttachedBehaviours:DragBehaviour.X"
                Value="{Binding RelativeSource={RelativeSource Self},Path=(GraphSharp_Controls:GraphCanvas.X),Mode=TwoWay}" />
        <Setter Property="WPFExtensions_AttachedBehaviours:DragBehaviour.Y"
                Value="{Binding RelativeSource={RelativeSource Self},Path=(GraphSharp_Controls:GraphCanvas.Y),Mode=TwoWay}" />
        <Setter Property="BorderThickness"
                Value="2" />
        <Setter Property="BorderBrush"
                Value="Transparent" />
        <Setter Property="Background">
            <Setter.Value>
                <LinearGradientBrush StartPoint="0,0"
                                     EndPoint="1,1">
                    <GradientStop Color="White"
                                  Offset="0" />
                    <GradientStop Color="BurlyWood"
                                  Offset="1" />
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
		<Setter Property="LayoutMode"
                    	    Value="{Binding RelativeSource={RelativeSource Self},Path=Vertex,Converter={StaticResource layoutModeConverter}}" />
					<Setter Property="WPFExtensions_AttachedBehaviours:DragBehaviour.IsDragEnabled"
                			Value="False" />
        <Style.Triggers>
            <Trigger Property="LayoutMode"
                     Value="Automatic">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type GraphSharp_Controls:CompoundVertexControl}">
                            <Border BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    Background="{TemplateBinding Background}">
                                <GroupBox>
                                    <GroupBox.Header>
                                        <ContentPresenter Content="{TemplateBinding Vertex}"/>
                                    </GroupBox.Header>

                                    <ItemsControl x:Name="PART_InnerCanvas"
                                                  ItemsSource="{TemplateBinding Vertices}">
                                        <ItemsControl.ItemsPanel>
                                            <ItemsPanelTemplate>
                                                <GraphSharp_Controls:GraphCanvas TextBlock.Foreground="Black">
													<GraphSharp_Controls:GraphCanvas.Background>
														<LinearGradientBrush StartPoint="0,0"
								                                             EndPoint="1,1">
								                            <GradientStop Color="White"
								                                          Offset="0" />
								                            <GradientStop Color="Silver"
								                                          Offset="1" />
								                        </LinearGradientBrush>
													</GraphSharp_Controls:GraphCanvas.Background>
												</GraphSharp_Controls:GraphCanvas>
                                            </ItemsPanelTemplate>
                                        </ItemsControl.ItemsPanel>
                                    </ItemsControl>
                                </GroupBox>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Setter Property="Background">
                    <Setter.Value>
                        <LinearGradientBrush StartPoint="0,0"
                                             EndPoint="1,1">
                            <GradientStop Color="White"
                                          Offset="0" />
                            <GradientStop Color="Silver"
                                          Offset="1" />
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
            </Trigger>
            <Trigger Property="GraphSharp_Controls:GraphElementBehaviour.IsHighlighted"
                     Value="True">
                <Setter Property="BorderBrush"
                        Value="Orange" />
                <Setter Property="BorderThickness"
                        Value="2" />
            </Trigger>
            <Trigger Property="GraphSharp_Controls:GraphElementBehaviour.IsSemiHighlighted"
                     Value="True">
                <Setter Property="BorderBrush"
                        Value="Yellow" />
                <Setter Property="BorderThickness"
                        Value="2" />
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="GraphSharp_Controls:GraphElementBehaviour.IsSemiHighlighted"
                               Value="True" />
                    <Condition Property="GraphSharp_Controls:GraphElementBehaviour.SemiHighlightInfo"
                               Value="Source" />
                </MultiTrigger.Conditions>
                <Setter Property="BorderBrush"
                        Value="Red" />
                <Setter Property="BorderThickness"
                        Value="2" />
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="GraphSharp_Controls:GraphElementBehaviour.IsSemiHighlighted"
                               Value="True" />
                    <Condition Property="GraphSharp_Controls:GraphElementBehaviour.SemiHighlightInfo"
                               Value="Target" />
                </MultiTrigger.Conditions>
                <Setter Property="BorderBrush"
                        Value="Blue" />
                <Setter Property="BorderThickness"
                        Value="2" />
            </MultiTrigger>
        </Style.Triggers>
            	</Style>
				
				<Style TargetType="{x:Type graph:VertexControl}">
					<Setter Property="WPFExtensions_AttachedBehaviours:DragBehaviour.IsDragEnabled"
                			Value="False" />
            	</Style>				
			</ResourceDictionary>
        </DockPanel.Resources>
        
        
        <Button Click="Relayout_Click"
                Content="Relayout"
                DockPanel.Dock="Top" />
        
        <Controls:ZoomControl>
            <graph:GraphLayout x:Name="layout" />
        </Controls:ZoomControl>
    </DockPanel>
</Window>
